{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "![](https://raw.githubusercontent.com/Qinbf/tf-model-zoo/master/README_IMG/01.jpg)\n",
    "AI MOOC： **www.ai-xlab.com**  \n",
    "如果你也是AI爱好者，可以添加我的微信一起交流：**sdxxqbf**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "from numpy import genfromtxt\n",
    "import matplotlib.pyplot as plt  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAD8CAYAAAB5Pm/hAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAGstJREFUeJzt3X2MXNdZx/Hvk/W23QTKNs22StY1\nTqXI5sUkblclYKlqHIpbGiWWKZDQQoCiCFFBKWBqCwQUtdjIoBb+oMi0QFBKmpCkTksBE8WpkCKc\nao3TumljEtrG9jrUixIXkSzN2nn4Y+5k17t3Zu7MfTv33N9Hsnbn7uzsmbve557znOeca+6OiIjE\n66K6GyAiIuVSoBcRiZwCvYhI5BToRUQip0AvIhI5BXoRkcgp0IuIRE6BXkQkcgr0IiKRW1N3AwAu\nu+wyX79+fd3NEBFplCNHjvy3u08Nel4QgX79+vXMzs7W3QwRkUYxs6eyPE+pGxGRyA0M9Gb2V2Z2\nxsy+vOzYPjN73My+ZGafNrPJZV/bbWZPmtlxM9tWVsNFRCSbLD36vwHetuLYA8D3u/sPAP8B7AYw\ns+8Fbga+L/mePzezscJaKyIiQxsY6N39X4FnVhz7F3c/lzw8DKxNPr8J+JS7f9vdvw48CbypwPaK\niMiQisjR/wLwT8nn08DJZV87lRwTE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7+x+Y2evp9GovBY4C73b3b9fX0mqZ2VuA33T3G9p4LpL3/Onk4Rrg\n79z9w2b2auBuYB1wAvgJd3+mpmZWysyuoTNJ/zLga8DPk/zN0LLzYWYXAyeB17v7t5Jjlf3fUKAX\nEYmcUjciIpFToBcRiZwCvYhI5BToRUQip0AvIhI5BXoRkcgp0IuIRE6BXkQkcv8P16YYQ+8fCuoA\nAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x27e6c80eb70>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 载入数据\n",
    "data = np.genfromtxt(\"data.csv\", delimiter=\",\")\n",
    "x_data = data[:,0,np.newaxis]\n",
    "y_data = data[:,1,np.newaxis]\n",
    "plt.scatter(x_data,y_data)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(100, 1)\n",
      "(100, 1)\n",
      "(100, 2)\n"
     ]
    }
   ],
   "source": [
    "print(np.mat(x_data).shape)\n",
    "print(np.mat(y_data).shape)\n",
    "# 给样本添加偏置项\n",
    "X_data = np.concatenate((np.ones((100,1)),x_data),axis=1)\n",
    "print(X_data.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 1.         32.50234527]\n",
      " [ 1.         53.42680403]\n",
      " [ 1.         61.53035803]]\n"
     ]
    }
   ],
   "source": [
    "print(X_data[:3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# 标准方程法求解回归参数\n",
    "def weights(xArr, yArr):\n",
    "    xMat = np.mat(xArr)\n",
    "    yMat = np.mat(yArr)\n",
    "    xTx = xMat.T*xMat # 矩阵乘法\n",
    "    # 计算矩阵的值,如果值为0，说明该矩阵没有逆矩阵\n",
    "    if np.linalg.det(xTx) == 0.0:\n",
    "        print(\"This matrix cannot do inverse\")\n",
    "        return\n",
    "    # xTx.I为xTx的逆矩阵\n",
    "    ws = xTx.I*xMat.T*yMat\n",
    "    return ws"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[7.99102098]\n",
      " [1.32243102]]\n"
     ]
    }
   ],
   "source": [
    "ws = weights(X_data,y_data)\n",
    "print(ws)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAD8CAYAAAB5Pm/hAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAIABJREFUeJzt3Xu8VXP+x/HXpxMJY7qISUkMlTsp\n0/mZIYUffg1mwmRQY/KLHwoZlGsuuUY3DI1bmZomYpKIojOh7VJKpZsmosvoQhm3Tp3z/f3x3Yfj\ndC77vtba+/18PHrss/dZe+/v2p39Wd/1Wd/v52vOOUREJH/VC7oBIiKSXQr0IiJ5ToFeRCTPKdCL\niOQ5BXoRkTynQC8ikucU6EVE8pwCvYhInlOgFxHJc/WDbgDA7rvv7lq3bh10M0REImXOnDkbnHPN\n6touFIG+devWzJ49O+hmiIhEipmtTGQ7pW5ERPJcnYHezB43s3VmtrDSY/ea2RIzm29mz5lZo0q/\nG2hmy81sqZn9d7YaLiIiiUmkR/8kcHKVx6YBhzjnDgOWAQMBzOwgoAdwcPw5D5lZUcZaKyIiSasz\n0DvnZgKfV3nsFefctvjdt4CW8Z9PB8Y757Y45z4ClgNHZ7C9IiKSpEzk6P8IvBT/uQXwaaXfrYo/\nJiIiAUk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TmxfiAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x27e6e8f00b8>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 画图\n",
    "x_test = np.array([[20],[80]])\n",
    "y_test = ws[0] + x_test*ws[1]\n",
    "plt.plot(x_data, y_data, 'b.')\n",
    "plt.plot(x_test, y_test, 'r')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
